<template>
<!-- 新增地址 -->
  <div>
    <van-nav-bar
      title="乐购"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <!-- <router-link to="/cart/order"> -->
    <div class="box">
      <ul>
        <li v-for="item in list" :key="item.id" @click="getAddress(item)">
          <div class="item">
            <p>{{ item.name }}</p>
            <div class="second">
              <p>{{ item.mobile }}</p>
              <p>{{ item.address }}</p>
            </div>
            <div class="icon"></div>
          </div>
        </li>
      </ul>
    </div>
    <router-link to="/cart/addAddress">
      <van-button @click="addAddress" type="danger" plain size="large"
        >新增地址</van-button
      >
    </router-link>
  </div>
</template>
<script>
import { getListAction } from "@/api/cart/addressEdit";
export default {
  data() {
    return {
      list: [],
      //   address: {},
    };
  },
  created() {
    this.init();
  },
  mounted() {},
  methods: {
    init() {
      getListAction({
        openId: localStorage.getItem("openId"),
      }).then((res) => {
        console.log(res);
        this.list = res.data;
      });
    },
    getAddress(val) {
      console.log(val);
      localStorage.setItem("addressId", val.id);
      this.$router.go(-1);
      // localStorage.setItem("address", val);
      // this.$router.push({ path: `/cart/addAddress`, query: { id: item.id } })
      //   var address = JSON.parse(localStorage.getItem("address"));
      //   if (address) {
      //     this.address = address;
      //   } else {
      //     this.address = res.address;
      //   }
   
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    addAddress(item) {
      console.log(item);
      this.$router.push({ path:'/cart/addAddress', query: { id: item.id } });
    },
  },
};
</script>

<style lang="scss">
.box {
  background-color: #fff;
  padding: 0.4rem 0;
  border-bottom: 1px solid #d9d9d9;
  width: 100%;
}
// .list {
//     width: 0.66667rem;
// }
.item {
  width: 100%;
  display: flex;
  justify-content: space-evenly;
  align-items: baseline;
  flex-direction: row;
  flex-wrap: wrap;
  align-content: stretch;
  padding: 0.4rem 0;
  border-bottom: 1px solid #d9d9d9;
}
.icon {
  width: 0.66667rem;
  height: 0.66667rem;
  margin: 0 0.26667rem;
  background: url(http://jinglins.gitee.io/legou/img/edit.d508a455.png)
    no-repeat;
  background-size: 100% 100%;
}
.van-button {
  bottom: 1px;
  position: fixed;
  left: 0px;
}
</style>